// Created by Joe on 2017/7/21.

/**
 * info<String>
 * time<Number>
 * top<Number>
 * panel: { show<String> }
 */

app.directive(
    'simpleNotice',
    [
        '$timeout',
        function ($timeout) {
            return {
                restrict: 'E',
                scope: {
                    info: '@',
                    time: '@',
                    top: '@',
                    panel: '='
                },
                template: '<div class="sn__setting"><span>{{info || "提示"}}</span></div>',
                link: function (scope, ele) {
                    ele.find('.sn__setting').css({
                        top: (scope.top || 600) + 'px',
                        width: (scope.panel.width || 800) + 'px',
                        marginLeft: -(scope.panel.width || 800) / 2 + 'px'
                    });

                    var timer = $timeout(function () {
                        if (scope.panel) {
                            scope.panel.show = false;
                        } else {
                            ele.css('display', 'none');
                        }
                    }, scope.time * 1000 || 3000);

                    ele.on('$destroy', function () {
                        $timeout.cancel(timer);
                    });
                }
            };
        }
    ]
);